package testing.dao;

import static org.junit.Assert.*;

import org.apache.struts2.ServletActionContext;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import service.IUserinfoService;
import service.impl.IUserinfoServiceImpl;

import dao.IUserinfoDAO;
import dao.impl.IUserinfoDAOImpl;
import entity.Userinfo;

public class TestIUserinfoDAOImpl {
	ApplicationContext context = null;
	IUserinfoDAO dao = null;
	IUserinfoService service = null;
	@Before
	public void setUp() throws Exception {
		context = new FileSystemXmlApplicationContext("classpath*:spring-config-*.xml"); 
		dao = (IUserinfoDAOImpl) context.getBean("userinfoDAO");
		service = (IUserinfoServiceImpl) context.getBean("userinfoService");
	}

	@After
	public void tearDown() throws Exception {
		context = null;
	}

	@Test
	public void testFindUserinfoByProperties() {
		
		Userinfo user = new Userinfo();
		user.setUsername("admin");
		user.setUserpwd("admin");
		Userinfo userinfo = null ;
		try {
			userinfo = dao.findUserinfoByProperties(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Assert.assertNotNull(userinfo);
		
		
		
		
		
	}
	/*
	@Test
	public void testGet() {
		Userinfo userinfo = null ;
		try {
			userinfo = dao.get((short)1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Assert.assertNotNull(userinfo);
	}*/
	@Test
	public void testGet2() {
		Userinfo user = new Userinfo();
		user.setUsername("admin");
		user.setUserpwd("admin");
		Userinfo userinfo = null ;
		try {
			userinfo = service.findUserinfoByProperties(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Assert.assertNotNull(userinfo);
		
	}
}
